package org.lh.ibernate.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import static org.lh.ibernate.common.IbernateConstant.PROPERTIES_LOCATION;

public class DbConfig {
    public static  String DRIVER;
    public static  String URL;
    public static  String USERNAME;
    public static  String PASSWORD;
    //数据库连接池初始化
    public static int INITCOUNT;
    //连接池不足的时候增长的步进值
    public static  int STEP;
    //数据库连接池的最大链接量
    public static  int MAXCOUNT;
    //dao存放的位置
    public static String DAO_PLACE;
    static  /*  在静态块里面的内容会在程序找到函数的主入口之前提前读取，因此数据库的密码和用户名以及驱动之类的东西会提前预备好  */
    {
        Properties proper=new Properties();
        InputStream in =DbConfig.class.getResourceAsStream(PROPERTIES_LOCATION);
        try {
            proper.load(in);
            DRIVER=proper.getProperty("driver");
            URL=proper.getProperty("url");
            USERNAME=proper.getProperty("username");
            PASSWORD=proper.getProperty("password");
            INITCOUNT=Integer.valueOf(proper.getProperty("initcount"));
            STEP=Integer.valueOf(proper.getProperty("step"));
            MAXCOUNT=Integer.valueOf(proper.getProperty("maxcount"));
            DAO_PLACE=proper.getProperty("dao-package");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
